<!doctype html>
<html lang="zh-CN">

<head>
    <meta charset="uft-8">
    <title>微用钱后台管理系统</title>
    <link rel="stylesheet" href="/public/css/loginpage.css">

    <script src="/public/js/layui/layui/layui.js"></script>
    <link rel="stylesheet" href="/public/js/layui/layui/css/layui.css">
    <script src="/public/js/jquery.min.js"></script>
</head>

<body>
    <div class="login-content">
        <div class="login-content-inner"></div>
        <div class="login-box">
            <h1>微用钱后台管理系统</h1>
            <div class="login-input-box layui-form">
                <div class="layui-form-item" style="margin-top:40px;">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="" placeholder="请输入账号" autocomplete="on" class="layui-input" id="val-username">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="" placeholder="请输入密码" autocomplete="new-password" class="layui-input" id="val-psw">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">验证码</label>
                    <div class="layui-input-block">
                        <input type="text" name="" placeholder="请输入验证码" autocomplete="on" class="layui-input" id="val-yzm" style="width:150px;float: left;">
                        <img src="/login/code" alt="captcha" style="width:130px;margin-left:10px;height: 38px;float: left;" title=" 点击切换二维码" id="yzm-img-btn">
                    </div>
                </div>
                <p id="login-msg" style="color:indianred;"></p>
                <div class="layui-btn" id="login-btn">登录</div>
            </div>
        </div>
    </div>
</body>
<script>
    layui.use("layer", function() {
        //   /login/login
        ///login/code

        var loadIndex = null;
        var layer = layui.layer;
        //点击登录
        $("#login-btn").on("click", function() {
            //&& $("#val-yzm").val()
            if ($("#val-username").val() && $("#val-psw").val()) {
                $.ajax({
                    type: "post",
                    url: "/login/login",
                    async: false,
                    dataType: "json",
                    data: {
                        username: $("#val-username").val(),
                        userpass: $("#val-psw").val(),
                        code: $("#val-yzm").val()
                    },
                    beforeSend: function() {
                        loadIndex = layer.load(0, {
                            shade: 0.5
                        });
                    },
                    success: function(d) {
                        if (d.result == "1") {

                            if (window.location.protocol == "http:") {
                                window.location.href = "http://" + window.location.host + "/index/home";
                            } else if (window.location.protocol == "https:") {
                                window.location.href = "https://" + window.location.host + "/index/home";
                            }

                        } else {
                            layer.close(loadIndex);
                            $("#login-msg").text(d.msg);
                        }
                    },
                    error: function() {
                        layer.close(loadIndex);
                        $("#login-msg").text("网络错误！");

                    }
                });
            } else if ($("#val-username").val() == "") {
                layer.msg("请输入账号！", {
                    icon: 0,
                    time: 1500
                });
            } else if ($("#val-psw").val() == "") {
                layer.msg("请输入密码！", {
                    icon: 0,
                    time: 1500
                });
            }
            // else if ($("#val-yzm").val() == "") {
            //     layer.msg("请输入验证！", {
            //         icon: 0,
            //         time: 1500
            //     });
            // } 
            else {
                layer.msg("请输入账号,密码，验证码！", {
                    icon: 0,
                    time: 1500
                });
            }
        });
        //点击验证码
        $("#yzm-img-btn").on("click", function() {
            $(this).attr("src", "/login/code?v=" + Math.ceil(Math.random() * 1000));
        });
    });
</script>

</html>